package com.jframe.sys.utils;

import java.net.URL;

public class FileUtil extends IOUtil{
 public static boolean delDir(String dir){		 
		 return IOUtil.delDirectory(dir);
	 }
	 
	 public static boolean del(String dirOrfile){
		 return IOUtil.delete(dirOrfile);
	 }
	 
	 public static long getFileSize(String path){
		 return IOUtil.getSize(path);
	 }
	 
	 public static String getFileType(String filePath){
		 filePath = StringUtil.null2Space(filePath);
		 int lastDot = filePath.lastIndexOf(".");
		 return filePath.substring(lastDot);
	 }
	 
	 public static String getFileName(String filePath){
		 filePath = StringUtil.null2Space(filePath);
		 int lastDot = filePath.lastIndexOf(".");
		 int lastS = filePath.lastIndexOf("/");
		 int lastS2 = filePath.lastIndexOf("\\");
		 int last = lastS > lastS2 ? lastS : lastS2;
		 return filePath.substring(last + 1,lastDot); 
	 }
	 
	 /**
	  * 获取目录名 jframe ver1.1
	  * @param filePath
	  * @return
	  */
	 public static String getDirName(String filePath){
		 filePath = IOUtil.winPath2UnixPath( StringUtil.null2Space(filePath)).trim();
		 int lastS = filePath.lastIndexOf("/");
		 if(lastS==filePath.length()-1){
			 filePath = filePath.substring(0,lastS);
			 lastS=filePath.lastIndexOf("/");
		 }
		 return filePath.substring(0,lastS+1 ); 	 
	 }
	 
	 public static String getFileFullName(String filePath){
		 filePath = StringUtil.null2Space(filePath);
		 int lastS = filePath.lastIndexOf("/");
		 int lastS2 = filePath.lastIndexOf("\\");
		 int last = lastS > lastS2 ? lastS : lastS2;
		 return filePath.substring(last + 1); 
	 }
	 /**
	  * 如果path参数时路径则返回true,否则返回false
	  * @param path
	  * @return
	  */
	 public static boolean isPath(String path){
		 
		 String tag1 = "/",tag2 = "\\";
		 if ( path.indexOf(tag1) > 0 ||path.indexOf(tag2)>0){
			 return true;
		 }
		 else {
			 return false;
		 }
	 }
	 
	 public static String getClzPath(Class clz){	
		 URL url = clz.getResource("");
		 if(url==null){
			url = clz.getProtectionDomain().getCodeSource().getLocation();
		 };
		 String path = url.getPath();
		
		 int idx = path.indexOf("/"); 
		 if(idx+1 <path.length()){
			 path = path.substring(idx +1);
			 return StringUtil.replace(path, "!", "");
		 }
		 else {
			 return "";
		 }
		 
		 
	 }
	 public static void main(String args[]){
		 
		// System.out.println(getDirName("c:\\dd\\sss/ss/"));
	 }
	/* 
	 public static String getFileMd5(String filePath){
		// public static String getFileMd5(String filePath)
		 return FileMD5Digest.getFileMd5(filePath);
	 }
	 
	 public static String getFileMd5(File file){
		 return FileMD5Digest.getFileMD5(file);
	 }*/
}
